extends Node

class_name Main
onready var _ballLight:Spatial=$ballLight
onready var _daDeng:Spatial=$daDeng
onready var _soundName:Label=$soundName
onready var _btnGmPanel:Button=$btnGmPanel
onready var _gmPanel=$gmPanel
onready var actorPlace=$actorPlace
func _ready():
	_setSoundName(SoundManger.lastSoundName)
	SoundManger.connect("playSound",self,'_onPlaySound')
	_btnGmPanel.connect("pressed",self,'_onBtnGmPanel')
	G.main=self
	G.djPos=$"台子/DjPos"
	
	yield(get_tree(),"idle_frame")
	DanMuReciver.start()



func _process(delta):
	_ballLight.rotate(Vector3(0,1,0),1*delta)
	_daDeng.rotate(Vector3(0,1,0),-1*delta)
	if Input.is_action_just_pressed("gm"):
		_gmPanel.show()
	if Input.is_action_just_pressed("add_user"):
		_add_user()
		pass

func _onPlaySound(soundName):
	_setSoundName(soundName)
	
func _setSoundName(soundName):
	_soundName.text='BGM:   '+soundName
	pass
func _onBtnGmPanel():
	_gmPanel.show()
func _add_user():
	var http=HTTPRequest.new()
	add_child(http)
	var uid=int(rand_range(1000,999999))
	http.connect('request_completed',self,'_on_request_url_completed',[http,uid],CONNECT_DEFERRED)
	var url='https://tenapi.cn/bilibili/?uid='+str(uid)
	http.request(url)
func _on_request_url_completed(result,response_code,headers,body,http,uid):
	http.queue_free()
	var json = parse_json(body.get_string_from_utf8())
	if json && json.get('code',0)==200:
		var data=json.get('data',{})
		var uName=data.get('name','')
		PlayerManager.addPlayer(uid,uName)
